package com.zyxi.autoflytest.suite.weather.api;

import cn.hutool.http.HttpUtil;
import com.zyxi.autoflytest.suite.weather.config.YoudaoConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * 有道词典接口
 * @author zhangkefei
 * @date 2021/8/20 22:39
 * @jdk 1.8
 */
@Component
public class YoudaoApi {

    @Autowired
    YoudaoConfig youdaoConfig;

    /**
     * 测试get请求demo
     * @param param
     * @return
     */
    public String getYoudao(String param){
        String url = youdaoConfig.getUrl();
        return HttpUtil.get(url+"?"+param);
    }

    /**
     * 测试post请求
     * @param param
     * @return
     */
    public String postYoudao(Map param){
        String url = youdaoConfig.getUrl();
        return HttpUtil.post(url,param);
    }

    public Object[][] params(){
        List<Map> params = youdaoConfig.getParams();
        Object[][] o = new Object[params.size()][1];
        for (int i = 0; i < params.size(); i++) {
            o[i] = new Object[]{params.get(i)};
        }
        return o;
    }
}
